import React, {Component } from 'react';
import SummaryStore from './SummaryStore'

class SummaryView extends Component{
    constructor(props){
        super(props);

        this.onChange = this.onChange.bind(this);
        this.state = {summary:SummaryStore.getSummary()};
    }

    onChange(){
        console.log("SummaryView onChange");
        this.setState({summary:SummaryStore.getSummary()});
    }

    componentDidMount(){
        SummaryStore.addChangeListener(this.onChange);
    }

    componentWillUnmount(){
        SummaryStore.removeChagneListener(this.onChange);
    }

    render(){
        return (
            <div style={{margin:50}}>
                
                <span style={{fontSize:30,marginLeft:50,marginRight:50}}>Summary:{this.state.summary}</span>
                
            </div>
        );
    };

}


export default SummaryView;
